package de.lulusoft.anothertorrent.gui.wizards;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

import de.lulusoft.anothertorrent.core.AnotherTorrentCore;
import de.lulusoft.anothertorrent.core.servers.Server;
import de.lulusoft.anothertorrent.core.servers.ServerManager;
import de.lulusoft.anothertorrent.gui.views.ServerView;

public class NewServerWizard extends Wizard implements INewWizard {
	
	public static final String ID = "de.lulusoft.anothertorrent.gui.wizards.NewServerWizard";
	
	private NewServerWizardPage newServerWizardPage = null;

	public NewServerWizard() {
		setWindowTitle(Messages.NewServerWizard_1);
	}

	@Override
	public void addPages() {
		newServerWizardPage = new NewServerWizardPage(Messages.NewServerWizard_2);
		addPage(newServerWizardPage);
	}

	@Override
	public boolean performFinish() {
		Server server = newServerWizardPage.getServer();
		ServerManager sm = AnotherTorrentCore.getDefault().getServerManager();
		sm.addServer(server);
		sm.save();
		ServerView.setInput(sm);
		return true;
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
	}

}
